package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Permission;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限Controller
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/22
 */
@RestController
@RequestMapping("/per")
@Api(value = "权限控制层", tags = "权限操作访问接口")
public class PermissionController {
    /**
     * 权限业务层
     */
    @Autowired
    private PermissionService permissionService;


    /**
     * 分类查询权限
     *
     * @param current    当前页
     * @param size       每页长度
     * @param permission 分类
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选权限信息")
    public JsonRequest<List<Permission>> lookPermission(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            Permission permission) {
        return permissionService.lookPermission(current, size, permission);
    }


    /**
     * 新增一条权限数据
     *
     * @param permission 权限信息
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条权限信息")
    public JsonRequest<Integer> insertOnePermission(
            @ApiParam(value = "待添加的权限信息", required = true)
            @RequestBody Permission permission) {
        return permissionService.insertOnePermission(permission);
    }

    /**
     * 修改一条权限数据
     *
     * @param permission 待修改的权限信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改一条权限信息")
    public JsonRequest<Integer> updateOnePermission(
            @ApiParam(value = "待修改的权限信息", required = true)
            @RequestBody Permission permission) {
        return permissionService.updateOnePermission(permission);
    }

    /**
     * 批量删除权限
     *
     * @param permissionId 权限ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除权限信息")
    public JsonRequest<Integer> deletePermissions(
            @ApiParam(value = "待删除的权限ID", required = true)
            @RequestBody List<String> permissionId) {
        return permissionService.deletePermissions(permissionId);
    }
}
